package com.edan.partnerback.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edan.partnerback.entity.Permission;
import com.edan.partnerback.mapper.PermissionMapper;
import com.edan.partnerback.service.IPermissionService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author edan
 * @since 2024-03-31
 */
@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements IPermissionService {

    @Override
    public List<Permission> childrenTree(Integer pid, List<Permission> allDate) {
        //一级目录
        List<Permission> list = new ArrayList<>();

        for (Permission permission : allDate) {
            //说明是当前层次，添加至数组即可
            if (Objects.equals(permission.getPid(), pid)) {
                list.add(permission);
                // 寻找当前目录的下一层目录
                permission.setChildren(childrenTree(permission.getId(), allDate));
            }
        }
        return list;
    }
}
